@extends('layouts.system_common')
@section('content')
    <script type="text/javascript">
        var element = document.getElementById("system_tab_5");
        element.classList.add("tab_selected");
    </script>
    <div class="breadcrumbs_container">
        {{ Breadcrumbs::render('customer.customer_info_change') }}
    </div>

    <div class="row">
        <div class="col-sm-3">会社名: {{$corpInfo->corp_name}}</div>
        <div class="col-sm-3">ID:{{$corpInfo->corp_id}}</div>
        <div class="col-sm-3">Pass:*****</div>
        <div class="col-sm-3" id="lyx_change_pwd"><a href="#">パスワード変更はこちらから</a></div>
    </div>

    <div class="row">
        <div class="col-sm-12">会社名カナ: {{$corpInfo->corp_catelogue}}</div>
    </div>

    <div class="row">
        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#e9ecef" size="3"/>
    </div>

    <form action="save" method="post" id="lyx_form">
        <?php echo csrf_field(); ?>
        @foreach($shopList as $value)
            <input name="shopInfo[{{$loop->index}}][shop_id]" type="hidden" value="{{$value->shop_id}}">
            <div class="form-group row">
                <label for="staticEmail" class="col-sm-2 col-form-label">店舗名{{$loop->iteration}}</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" value="{{$value->shop_name}}"
                           name="shopInfo[{{$loop->index}}][shop_name]">
                </div>
            </div>

            <div class="form-group row">
                <label for="inputPassword" class="col-sm-2 col-form-label">住所</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" value="{{$value->shop_adress}}"
                           name="shopInfo[{{$loop->index}}][shop_adress]">
                </div>
            </div>
            <div class="form-group row">
                <label for="inputPassword" class="col-sm-2 col-form-label">住所(ビル名)</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" value="{{$value->shop_biru_name}}"
                           name="shopInfo[{{$loop->index}}][shop_biru_name]">
                </div>
            </div>

            <div class="form-group row">
                <label for="inputPassword" class="col-sm-2 col-form-label">会社TEL</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" value="{{$value->shop_telephone_number}}"
                           name="shopInfo[{{$loop->index}}][shop_telephone_number]">
                </div>

                <label for="inputPassword" class="col-sm-2 col-form-label">会社FAX</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" value="{{$value->shop_fax_number}}"
                           name="shopInfo[{{$loop->index}}][shop_fax_number]">
                </div>
            </div>

            <div class="form-group row">
                <label for="inputPassword" class="col-sm-2 col-form-label">代表Mail</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" value="{{$value->shop_mail}}" placeholder="●●●@●●"
                           name="shopInfo[{{$loop->index}}][shop_mail]">
                </div>
            </div>


            <div class="form-group row">
                <label for="inputPassword" class="col-sm-2 col-form-label">担当者</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" value="{{$value->stuff_name}}"
                           name="shopInfo[{{$loop->index}}][stuff_name]">
                </div>

                <label for="inputPassword" class="col-sm-2 col-form-label">担当TEL</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" value="{{$value->shop_tel}}"
                           name="shopInfo[{{$loop->index}}][shop_tel]">
                </div>

            </div>

            <div class="row">
                <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#e9ecef" size="3"/>
            </div>

        @endforeach

        <div class="form-group row">
            <button class="btn btn-danger" id="lyx_submit">保存</button>
        </div>
    </form>

    <script>
        $('#lyx_submit').on('click', function () {

            var data = $('#lyx_form').serialize();
            $.ajax({
                url: '{{url("customer/customer_info_save")}}',
                type: 'post',
                data: data,
                success: function (retData) {
                    if (retData.code == 1001) {
                        successAlert(retData.msg, 'customer_info_change');
                    } else {
                        layuiTopMsg(retData.msg);
                    }
                }
            })
            return false;
        })


        $('#lyx_change_pwd').on('click', function () {
            layer.prompt({
                title: '新しいパスワードを入力する',
            }, function (value, index, elem) {
                change_pwd(value);
                layer.close(index);
            });
        })

        function change_pwd(pwd) {
            hdAjax({
                url: '{{url("customer/change_pwd")}}',
                data: {password: pwd},
                success: function (retData) {
                    if (retData.code == 1001) {
                        successAlert('パスワードを修正して成功する', 'customer_info_change');
                    } else {
                        layuiTopMsg(retData.msg);
                    }
                }
            })
        }


    </script>
@endsection
